\defmodule{RandomStreamManager}

Manages a list of random streams for more convenient synchronization.
All streams in the list can be reset simultaneously by a single 
call to the appropriate method of this stream manager,
instead of calling explicitly the reset method for each 
individual stream.

After a random stream manager is constructed, any
existing \class{RandomStream} object can be registered
to this stream manager (i.e., added to the list)
and eventually unregistered (removed from the list).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\bigskip\hrule

\begin{code}
\begin{hide}
/*
 * Class:        RandomStreamManager
 * Description:  Manages a list of random streams
 * Environment:  Java
 * Software:     SSJ 
 * Copyright (C) 2001  Pierre L'Ecuyer and Universite de Montreal
 * Organization: DIRO, Universite de Montreal
 * @author       
 * @since

 * SSJ is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License (GPL) as published by the
 * Free Software Foundation, either version 3 of the License, or
 * any later version.

 * SSJ is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * A copy of the GNU General Public License is available at
   <a href="http://www.gnu.org/licenses">GPL licence site</a>.
 */
\end{hide}
package umontreal.iro.lecuyer.rng;\begin{hide}

import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import umontreal.iro.lecuyer.rng.RandomStream;
\end{hide}

public class RandomStreamManager\begin{hide} {
   private List streams = new ArrayList();
\end{hide}

   public RandomStream add (RandomStream stream)\begin{hide} {
      if (stream == null)
         throw new NullPointerException();
      if (streams.contains (stream))
         return stream;
      streams.add (stream);
      return stream;
   }\end{hide}
\end{code}
\begin{tabb}   Adds the given \texttt{stream} to the internal list of
 this random stream manager and returns the added stream.
\end{tabb}
\begin{htmlonly}
   \param{stream}{the stream being added.}
   \return{the added stream.}
   \exception{NullPointerException}{if \texttt{stream} is \texttt{null}.}
\end{htmlonly}
\begin{code}

   public boolean remove (RandomStream stream)\begin{hide} {
      return streams.remove (stream);
   }\end{hide}
\end{code}
\begin{tabb}   Removes the given stream from the internal list of this random
 stream manager.  Returns \texttt{true} if the stream was
 properly removed, \texttt{false} otherwise.
\end{tabb}
\begin{htmlonly}
   \param{stream}{the stream being removed.}
   \return{the success indicator of the operation.}
\end{htmlonly}
\begin{code}

   public void clear()\begin{hide} {
      streams.clear();
   }\end{hide}
\end{code}
\begin{tabb}   Removes all the streams from the internal list
 of this random stream manager.
\end{tabb}
\begin{code}

   public List getStreams()\begin{hide} {
      return Collections.unmodifiableList (streams);
   }\end{hide}
\end{code}
\begin{tabb}   Returns an unmodifiable list containing all the
 random streams in this random
 stream manager.  The returned list, constructed by
 \externalmethod{java.util}{Collections}{unmodifiableList}{(List)}, can be assumed
 to contain non-\texttt{null} \class{RandomStream} instances.
\end{tabb}
\begin{htmlonly}
   \return{the list of managed random streams.}
\end{htmlonly}
\begin{code}

   public void resetStartStream()\begin{hide} {
      for (int s = 0; s < streams.size(); s++)
         ((RandomStream)streams.get (s)).resetStartStream();
   }\end{hide}
\end{code}
\begin{tabb}   Forwards to the
 \externalmethod{umontreal.iro.lecuyer.rng}{RandomStream}{resetStartStream}{()} methods
 of all streams in the list.
\end{tabb}
\begin{code}

   public void resetStartSubstream()\begin{hide} {
      for (int s = 0; s < streams.size(); s++)
         ((RandomStream)streams.get (s)).resetStartSubstream();
   }\end{hide}
\end{code}
\begin{tabb}   Forwards to the
 \externalmethod{umontreal.iro.lecuyer.rng}{RandomStream}{resetStartSubstream}{()} methods
 of all streams in the list.
\end{tabb}
\begin{code}

   public void resetNextSubstream()\begin{hide} {
      for (int s = 0; s < streams.size(); s++)
         ((RandomStream)streams.get (s)).resetNextSubstream();
   }\end{hide}
\end{code}
\begin{tabb}   Forwards to the
 \externalmethod{umontreal.iro.lecuyer.rng}{RandomStream}{resetNextSubstream}{()} methods
 of all streams in the list.
\end{tabb}
\begin{code}\begin{hide}

   public String toString() {
      StringBuffer sb = new StringBuffer (getClass().getName());
      sb.append ('[');
      sb.append ("number of stored streams: ").append (streams.size());
      sb.append (']');
      return sb.toString();
   }
}\end{hide}
\end{code}
